// 1
function assembleChars(string){
    let arr =[];
    // of 遍历字符
    for(let s of string){
        // 查找数组中是否存在字符 是在指定下标后追加，否直接追加
        if(arr.indexOf(s) == -1)
            arr.push(s)
        else
            arr.splice(arr.indexOf(s),0,s)
    }
    console.log(arr.join(''))
    return arr.join('');
}
assembleChars('ejfjdfoijdf')

// 2
function lodashJoinToCamelCase(string){
    let s = '';
    // 将字符转化为数组 遍历，截取第一个字母转化为大写+除了第一个字符以外字符
    string.split('_').forEach((item) =>  s = s+item.substring(0, 1).toUpperCase()+item.substring(1))
    return s;
}
lodashJoinToCamelCase('bbb_aaa_ccc');

// 3

//4
function countCharactors(string){
    let arr = [];
    // of 遍历字符
    for(let s of string){
        // 如果数组长度大于1，进入循环 否则push对象
        if(arr.filter((i) => i.char === s).length){
            // 遍历 查找是否字符已在数组中存在
            arr.forEach((item,index) => {
                // 若存在 count、percent重新计算
                if(item.char === s){
                    arr[index].count =  arr[index].count + 1;
                    arr[index].percent =  ((arr[index].count / string.length) *100).toFixed(0) + '%';
                }
            })
        }else{
            arr.push({
                char:s,
                count:1,
                percent: ((1 / string.length)*100).toFixed(0) + '%'
            })
        }
    }
    console.log(arr)
    return arr;
}
countCharactors('ww89');

// 5
function convertExcelColumnCodeToNumber(text){
    // 生成 26个字母组合
    let charArr =  [...Array(26)].map((v,i) => String.fromCharCode(i + 65));
    let charArr1 = [];
    //生成 AA BB CC数组组合
    charArr.forEach((i,x)=>{
        charArr.forEach((e,y)=>{
            charArr1.push(`${i+e}`);
        })
    })
    // 合并数组
    let charArrs = charArr.concat(charArr1);
    let index = charArrs.findIndex((item) => {return item === text})
    return index + 1;
}
convertExcelColumnCodeToNumber('GG')

// 6
let results =[];
function getAllleftbName(tree=[]){
    // 遍历tree
    tree.forEach((item,index) => {
        results.push({name:item.name}); 
        if(item.children && item.children.length) {
            getAllleftbName(item.children);
        }
    })
    return results;
}
let tree = [{
    name:1,
    children:[{
        name:2,
        children:[{
            name:3,
            children:[{
                name:4
            }]
        }]
    }]
}]
getAllleftbName(tree)
